package com.test.schoolhelper.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;

public class Tools {


    private static Random random = new Random();

    public static String generatePhoneNumber() {
        StringBuilder phoneNumber = new StringBuilder("1");
        phoneNumber.append(random.nextInt(7) + 3);
        for (int i = 0; i < 9; i++) {
            phoneNumber.append(random.nextInt(10));
        }
        return phoneNumber.toString();
    }

    /**
     * 自定义格式化时间
     *
     * @param date
     * @param pattern
     * @return
     */
    public static String customFormat(Date date, String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, Locale.CHINA);
        return simpleDateFormat.format(date);
    }

    /**
     * 字符串转时间戳
     *
     * @param time
     * @return
     */
    public static long strToLong(String time, String pattern) {
        SimpleDateFormat sdr = new SimpleDateFormat(pattern, Locale.CHINA);
        Date date;
        long l = 0;
        try {
            date = sdr.parse(time);
            l = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return l;
    }

    public static int getNum(int startNum,int endNum){
        if(endNum > startNum){
            Random random = new Random();
            return random.nextInt(endNum - startNum) + startNum;
        }
        return 0;
    }


}
